package com.github.base.service.impl;

import com.github.base.domain.Log;
import com.github.base.dto.log.LogDTO;
import com.github.base.exception.CommonException;
import com.github.base.global.Const;
import com.github.base.mapper.LogMapper;
import com.github.base.service.LogService;
import com.github.base.vo.log.LogListVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Slf4j
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public Page<LogListVO> pageList(LogDTO logDTO) {
        Page<LogListVO> page = new Page<>(logDTO.getPageNumber(), logDTO.getPageSize());
        logMapper.findListByPage(page, logDTO);
        return page;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Integer id) {
        Log log = getById(id);
        if (log == null) {
            throw new CommonException("日志信息不存在！");
        }
        log.setState(Const.NO);
        log.updateById();
    }
}
